package com.scau.dunka.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MybatisUtil {
    private  static SqlSessionFactory sessionFactory;
    public static SqlSession openSession(){
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        try {
            InputStream inputStream = Resources.getResourceAsStream("config.xml");
            sessionFactory = builder.build(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sessionFactory.openSession();
    }

}
